#ifndef _CC1101_H_
#define _CC1101_H_

#include "CC1101_REG.h"
#include "spi_cc1101.h"

// RF_SETTINGS is a data structure which contains all relevant CCxxx0 registers
typedef struct S_RF_SETTINGS
{
    INT8U IOCFG0;   // GDO0 output pin configuration
    INT8U PKTCTRL0;  // Packet automation control.
    INT8U FSCTRL1;   // Frequency synthesizer control.
    INT8U FREQ2;     // Frequency control word, high INT8U.
    INT8U FREQ1;     // Frequency control word, middle INT8U.
    INT8U FREQ0;     // Frequency control word, low INT8U.
    INT8U MDMCFG4;   // Modem configuration.
    INT8U MDMCFG3;   // Modem configuration.
    INT8U MDMCFG2;   // Modem configuration.
    INT8U DEVIATN;   // Modem deviation setting (when FSK modulation is enabled).
    INT8U MCSM0;     // Main Radio Control State Machine configuration.
    INT8U FOCCFG;    // Frequency Offset Compensation Configuration.
    INT8U BSCFG;     // Bit synchronization Configuration.
    INT8U AGCCTRL2;  // AGC control.
    INT8U AGCCTRL1;  // AGC control.
    INT8U AGCCTRL0;  // AGC control.
    INT8U WORCTRL;
    INT8U FREND1;    // Front end RX configuration.
    INT8U FSCAL3;    // Frequency synthesizer calibration.
    INT8U FSCAL2;    // Frequency synthesizer calibration.
    INT8U FSCAL1;    // Frequency synthesizer calibration.
    INT8U FSCAL0;    // Frequency synthesizer calibration.
    INT8U TEST0;     // Various test settings.

    INT8U FSTEST;    // Frequency synthesizer calibration control
    INT8U TEST2;     // Various test settings.
    INT8U TEST1;     // Various test settings.
    INT8U IOCFG2;    // GDO2 output pin configuration
    INT8U PKTCTRL1;  // Packet automation control.
    INT8U ADDR;      // Device address.
    INT8U PKTLEN;    // Packet length.
    INT8U FSCTRL0;   // Frequency synthesizer control.
    INT8U MDMCFG1;   // Modem configuration.
    INT8U MDMCFG0;   // Modem configuration.
    INT8U CHANNR;    // Channel number.
    INT8U FREND0;    // Front end RX configuration.
    INT8U FSCTRL2;		//自已加的
} RF_SETTINGS;

extern uint8 tx[50];
extern uint8 rxBuffer[50];
extern u8 PaTabel[8];

/*
================================================================================
-----------------------------------macro definitions----------------------------
================================================================================
*/
typedef enum { TX_MODE, RX_MODE }TRMODE;
typedef enum { BROAD_ALL, BROAD_NO, BROAD_0, BROAD_0AND255 }ADDR_MODE;
typedef enum { BROADCAST, ADDRESS_CHECK} TX_DATA_MODE;

/*
================================================================================
-------------------------------------exported APIs------------------------------
================================================================================
*/

/*Initialize the CC1101, User can modify it*/
void CC_Init(void);
void CC1101PowerReset(void);
void halRfWriteRfSettings(void);
///*Set the SYNC bytes of the CC1101*/
void CC1101SetSYNC( uint16 sync );

uint8 halSpiReadReg( uint8 addr );
void halSpiWriteReg( uint8 addr, uint8 value );
uint8 halSpiStrobe(uint8 addr);
void halSpiWriteBurstReg( uint8 *buffer, uint8 count );
void halSpiReadBurstReg( uint8 *buffer, uint8 count );

uint8 halRfReceivePacket(uint8 *rxBuffer, uint8 *length);
uint8 sendTxBufCmd(uint8 *pucData, uint16 usLength, TX_DATA_MODE mode);


/*Set the address and address mode of the CC1101*/
void CC1101SetAddress( uint8 address, ADDR_MODE AddressMode);

void setChannel(uint8 channel);

uint8 halReadRssi(void);

/*Set the device as TX mode or RX mode*/
void CC1101SetTRMode( TRMODE mode );

/*Set the CC1101 into IDLE mode*/
void CC1101SetIdle( void );

/*Set the CC1101 into SLEEP mode*/
void CC1101SetPWD( void );


#endif // _CC1101_H_
/*
================================================================================
------------------------------------THE END-------------------------------------
================================================================================
*/
